<!-- Student_FreeCourseFileNew.html -->
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>自由课程文件/文件夹</title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<style type="text/css" media="screen">
			.feeling {
				padding: 10px;
				margin-top: 10px;
			}
			.feeling-text {
				word-break: break-all;
			}
			.mui-table-view-cell > a:not(.mui-btn) {
				padding-left: 4px;
			}
			.mui-table-view .mui-media-object.mui-pull-left {
				margin-right: 4px;
			}
			.message_title {
				width: 100%;
			}
			.mui-table-view-cell p {
				height: 24px;
			}
			.file_size {
				margin-left: 40px;
			}
			.download_img {
				width: 20px;
				margin-bottom: 4px;
			}
			.download_progress {
				background-color: rgba(24,180,237,0.25);
				height: 100%;
				width: 0;
				position: absolute;
				left: 0;
				top: 0;
			}
		</style>
	</head>
	<body>
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div id="header" class="base_navigation_bar base_style_color base_navigation_item_bar">
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span id="nav_title"></span>
			<!-- <a class="base_right_item" id="bewriteBtn" onclick="openbewrite()" hidden="hidden">描述</a> -->
		</div>
		<div id="main" class="base_content_div">
			<div id="bewriteDIV" hidden="hidden">
				<div class="padding10" style="background-color: white;">
					<p class=" base_black_grey base_title_font">
						描述
					</p>
					<div class="base_dark_grey base_content_font according-2-rows text_indent_2" id="bewrite" onclick="openBewrite()">
						描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字
					</div>
				</div>
				<!-- <div class="div_divider"></div>
				<div style="background-color: #f0f0f0;height:5px"></div> -->
				<div class="div_divider"></div>
			</div>
			<!-- <div class="feeling" hidden="hidden">
				<p class="title base_title_font">
					描述
				</p>
				<div class="feeling-text base_content_font">
					<p id="course_info">
						暂无描述
					</p>
				</div>
			</div> -->
			<ul id="file_list" class="mui-table-view" style="margin-top: 10px;">
				<!-- <li class="mui-table-view-cell mui-media">
				<a href="javascript:;">
				<img class="mui-media-object mui-pull-left" style="padding: 6px;" src="../../image/icon_wenjia01.png" >
				<div class="mui-media-body">
				<p class="mui-ellipsis base_dark_grey font14">
				<span class="message_title">
				超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名超长文件名
				</span>
				</p>
				<p class='mui-ellipsis base_light_gray font12 content_p'>
				<span class="message_content">
				<span class="file_submit_time">
				2017-01-02 14:20
				</span>
				<span class="file_size">
				1.5MB
				</span>
				</span>
				<img src="../../image/iconO_xiazai.png" alt="" class="download_img">
				</p>
				</div>
				</a>
				</li> -->
			</ul>
			<div class="noSign"  id="noData"  hidden="hidden">
				<img src="../../image/icon_img.png" width="60%">
				<p class="font16 top_15 base_dark_grey" >
					该文件夹暂无内容
				</p>
			</div>
			<div class="loadFailure" hidden="hidden" id="noNet">
				<img src="../../image/icon_img01.png" width="60%">
				<p class="" >
					数据加载失败
				</p>
				<p>
					请检查您的网络
				</p>
				<button type="button" class="mui-btn mui-btn-outlined" onclick="setupFolerFiles()">
					重新加载
				</button>
			</div>
		</div>
	</body>
	<script src="../../script/jquery.min.js"></script>
	<script src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/attachmentManager.js"></script>
	<script type="text/javascript" src="../../script/getToken.js"></script>
	<script type="text/javascript">
		apiready = function() {
			// setupFiles();
			$('#nav_title').text(api.pageParam.cdetailtitle);
			// setupShowOrHideInfo(api.pageParam.is_dis_bewrite);
			setupFile();
			setupNotifi();
			setupBewriteShowOrHide();
			bewrite();
		}
		function bewrite() {
			var pageParam = api.pageParam;
			var bewrite = pageParam.bewrite;
		    if (bewrite != "" && bewrite != null && bewrite != undefined) {
		        $('#bewriteDIV').show();
		        if(removeHTMLTag(bewrite).length > 0){
					$('#bewrite').text(removeHTMLTag(bewrite));
				}else{
					$('#bewrite').text('点击查看详情');
				}
			}
		}
		function openBewrite(){
			api.openWin({useWKWebView:true,
			    name: 'Student_Free_bewrite',
			    url: 'Student_Free_bewrite.html',
			    pageParam: {
			        cdetailtitle : api.pageParam.cdetailtitle,
					bewrite : api.pageParam.bewrite,
					is_dis_bewrite : api.pageParam.is_dis_bewrite
			    }
			});
		}
		function setupBewriteShowOrHide(){
			if (api.pageParam.is_dis_bewrite == 1) {
				$('#bewriteBtn').show();
			}else{
				$('#bewriteBtn').hide();
			}
		}
		function setupShowOrHideInfo(showInfo){
			if (showInfo == '1') {
				$('.feeling').show();
				setupInfo(api.pageParam.bewrite);
			}else{
				$('.feeling').hide();
			}
		}
		//设置描述信息
		function setupInfo(infoData){
			$('#course_info').html(infoData);
			setupImage();
		}
		function setupImage() {
			var newWidth = api.winWidth - 100;
			$("img").each(function(i) {
				var oldWith = $(this).width();
				if(oldWith == 0){
					setTimeout(function(){
						setupImage();
					}, 500);
					return;
				}
				// alert('oldWith:'+oldWith+'\nnewWidth'+newWidth);
				if (oldWith > newWidth) {
					var oldHeight = $(this).height();
					var newHeight = oldHeight * (newWidth / oldWith);
					$(this).width(newWidth);
					$(this).height(newHeight);
				} else {
					// $(this).width(newWidth);
				}
			});
		}
		function setupFile() {
			var pageParam = api.pageParam;
			if (pageParam.content_type == 'files') {
				loadFileData();
			} else {
				var fileName = pageParam.cdetailtitle;
				var fileData = {
					fileName : fileName,
					id : pageParam.id,
					content_type : pageParam.content_type
				};
				// alert(JSON.stringify(fileData));
				// $('#file_list').html(fileAndFolderHtmlString(fileData));
				// addFileCellClick();
				setupFolerFiles();
			}
		}

		function loadFileData() {
			var pageParam = api.pageParam;
			//		var fileUrl = "http://base.cfnet.org.cn/course/Videodetail/getfile";
			var params = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				cid : pageParam.cid,
				vid : pageParam.id,
				pid : pageParam.pid
			};
			cfnetppPOST(url_getfile, params, true, function(data, status) {
				if (status == 'success') {
					if (data.status == true) {
						var json = data.json;
						var filePath = json.filepath.filepath;
						filePath = filePath.replace('bcs.duapp.com/cfnetdoc', 'cfnetdoc.cfnet.org.cn');
						var fileName = filePath.substr(filePath.lastIndexOf('\/') + 1);
						var fileid = MD5(filePath);
						var fileData = {
							fileName : fileName,
							names : json.filepath.filename,
							filename : fileName,
							filePath : filePath,
							id : pageParam.id,
							content_type : pageParam.content_type,
							fileid : fileid
						};
						$('#file_list').html(fileAndFolderHtmlString(fileData));
						setupFileStatus(fileData);
						addFileCellClick();
					} else {
						api.toast({
							msg : '获取文件数据失败'
						});
					}
				} else {
					api.toast({
						msg : '网络异常'
					});
				}
			});
		}

		function setupFiles() {
			var pageParam = api.pageParam;
			var rid = pageParam.rid;
			var fileInfo = pageParam.bewrite;
			$('#course_info').html(fileInfo);
			var cdetailtitle = pageParam.cdetailtitle;
			$('#nav_title').text(cdetailtitle);
			if (pageParam.content_type == 'files') {//文件
				var ridArr = rid.split('||');
				if (ridArr != null && ridArr.constructor == Array && ridArr.length == 2) {
					var fileName = ridArr[0];
					var filePath = ridArr[1];
					var fileid = MD5(filePath);
					var fileData = {
						fileName : fileName,
						filePath : filePath,
						id : pageParam.id,
						content_type : pageParam.content_type,
						fileid : fileid
					};
					$('#file_list').html(fileAndFolderHtmlString(fileData));
					setupFileStatus(fileData);
					addFileCellClick();
				} else {
					api.toast({
						msg : '暂无数据'
					});
				}
			} else {
				var fileName = pageParam.cdetailtitle;
				var fileData = {
					fileName : fileName,
					id : pageParam.id,
					content_type : pageParam.content_type
				};
				$('#file_list').html(fileAndFolderHtmlString(fileData));
				// addFileCellClick();
				setupFolerFiles();
			}
		}
		function setupFolerFiles(){
			var pageParam = api.pageParam;
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				cid : pageParam.cid,
				vid : pageParam.id,
				pid : pageParam.pid
			};
			cfnetppPOST(url_getfolder,
			param,
			true,
			function(data, status){
				if (status == 'success') {
					if (data.status == true && data.code == 200) {
						var json = data.json;
						var folderFiles = json;
	//					alert(JSON.stringify(folderFiles))
						if (folderFiles != null ) {
							$('.noSign').hide();
			    			$('.loadFailure').hide();
							setupFilesHtml(folderFiles);
						}else{
							api.toast({
							    msg: '该文件夹暂无内容'
							});
							$('.noSign').show();
			    			$('.loadFailure').hide();
						}
					}else{
						api.toast({
						    msg: '该文件夹暂无内容'
						});
						$('.noSign').show();
		    			$('.loadFailure').hide();
					}
				}else{
					api.toast({
					    msg: '加载失败'
					});
					$('.noSign').hide();
	    			$('.loadFailure').show();
				}
			});
		}
		//设置文件列表
		function setupFilesHtml(list){
		 	var files=list.filepath;
			var filesHtmlString = '';
			for (var i = 0; i < files.length; i++) {
				var fileData = files[i];
				var filePath = fileData.realurl;
				filePath = filePath.replace('bcs.duapp.com/cfnetdoc', 'cfnetdoc.cfnet.org.cn');
				var fileid = MD5(filePath);
				var filename = filePath.substr(filePath.lastIndexOf('\/')+1);
				fileData["fileid"] = fileid;
				fileData["filename"] = filename;
				// fileData["fileid"] = fileData.id;
				// fileData["filename"] = fileData.names;
				fileData["filepath"] = filePath;
				$('#file_list').append(fileHtmlString(fileData));
				setupFileStatus(fileData);
			}
			setupFileClick();
		}
		function setupFileStatus(fileData) {
			var fs = api.require('fs');
			var fileid = fileData.fileid;
			var filePath = api.cacheDir + '/freeCourseFile/' + fileid + '/' + fileData.filename;
			fs.exist({
				path : filePath
			}, function(ret, err) {
				if (ret.exist) {//存在
					//ret.directory==true文件夹否为文件
					$('#' + fileid).removeClass('isNotDownload');
					$('#' + fileid).addClass('isDownload');
					$('#' + fileid).hide();
				} else {//不存在
					$('#' + fileid).removeClass('isDownload');
					$('#' + fileid).addClass('isNotDownload');
					$('#' + fileid).attr('src', '../../image/iconO_xiazai.png');
					$('#' + fileid).show();
				}
			});
		}
		function imagePathWithUrlPath(data){
			var filePath = data.filename;
			if (data.content_type == 'files') {
				filePath = data.fileName;
			}
			if (filePath == undefined || filePath == null || filePath == '') {
				if (data.content_type == 'files') {
					return '../../image/icon_wenjia01.png';
				}else{
					return '../../image/icon_wenjianjia.png';
				}
			}
			var fileSuffix = fileSuffixWithPath(filePath);
			if (fileSuffix == '.doc' || fileSuffix == '.docx') {
				return '../../image/icon_chapter_doc.png';
			}else if(fileSuffix == '.pdf'){
				return '../../image/icon_chapter_pdf.png';
			}else if(fileSuffix == '.xls' || fileSuffix == '.xlsx'){
				return '../../image/icon_chapter_excel.png';
			}else if(fileSuffix == '.ppt' || fileSuffix == '.pptx'){
				return '../../image/icon_chapter_ppt.png';
			}else if(fileSuffix == '.png' || fileSuffix == '.jpg' || fileSuffix == '.jpeg' || fileSuffix == '.bmp' || fileSuffix == '.gif'){
				return '../../image/icon_chapter_img.png';
			}else if(fileSuffix == '.mp4' || fileSuffix == '.avi' || fileSuffix == '.rmvb' || fileSuffix == '.3gp' || fileSuffix == '.flv'){
				return '../../image/09.png';
			}else{
				if (data.content_type == 'files') {
					return '../../image/icon_wenjia01.png';
				}else{
					return '../../image/icon_wenjianjia.png';
				}
			}
		}
		function fileSuffixWithPath(path){
			var result =/\.[^\.]+/.exec(path);
			return result;
		}
		function fileHtmlString(data){
			var imgPath = imagePathWithUrlPath(data);
			return '<li class="mui-table-view-cell mui-media folder_file_cell" file_name="'+data.filename+'" file_path="'+data.filepath+'" is_encr="'+data.is_encr+'" baidu_cloud_id="'+data.baidu_cloud_id+'" baidu_cloud_id_url="'+data.baidu_cloud_id_url+'">'+
					'<div id="progress'+data.fileid+'" class="download_progress"></div>'+
					'<a href="javascript:;">'+
						'<img class="mui-media-object mui-pull-left" style="padding: 6px;" src="'+imgPath+'" >'+
						'<div class="mui-media-body">'+
							'<p class="mui-ellipsis base_dark_grey font14">'+
								'<span class="message_title">'+
									data.names+
								'</span>'+  
							'</p>'+
							'<p class="mui-ellipsis base_light_gray font12 content_p">'+
								'<span class="message_content">'+
									// '<span class="file_submit_time">\
									// 	2017-01-02 14:20\
									// </span>'+//旧接口未返回时间暂不显示
									// '<span class="file_size">\
									// 	1.5MB\
									// </span>'+//旧接口未返回大小暂不显示
								'</span>'+
								// '<img id="'+data.fileid+'" src="../../image/iconO_xiazai.png" alt="" class="download_img" file_name="'+data.filename+'" file_path="'+data.filepath+'" hidden="hidden">'+
							'</p>'+
						'</div>'+
					'</a>'+
				'</li>';
		}
		function setupFileClick(){
			$('.folder_file_cell').unbind('click');
			$('.folder_file_cell').click(function(){
				var doc = $(this).attr('file_path');
				var title = $(this).attr('file_name');
				var is_encr = $(this).attr('is_encr');
				var baidu_cloud_id = $(this).attr('baidu_cloud_id');
				var baidu_cloud_id_url = $(this).attr('baidu_cloud_id_url');
				var fileid = MD5(doc);
				if ($('#'+fileid).hasClass('isDownload')) {
					openLocalFile(api.cacheDir + '/freeCourseFile/' + fileid + '/' + title);
				}else{
					var arr = new Array('jpg', 'png', 'jpeg', 'bmp');
					var gifArr = new Array('gif');
					var arr1 = new Array('swf', 'mp4');
					var ext = doc.replace(/.+\./, "");
				
					if (gifArr.toString().indexOf(ext) > -1){
						openGif(doc);
					}else if (arr.toString().indexOf(ext) > -1) {
						openImage(doc);
					} else {
						if (arr1.toString().indexOf(ext) > -1) {
							var connectionType = api.connectionType;
				            if (connectionType != 'wifi' && connectionType != 'none') {
				            	api.confirm({
				                    title: '提示',
				                    msg: '您当前处于移动数据网络下，是否继续播放',
				                    buttons: ['确定', '取消']
				                }, function(ret, err) {
				                    var index = ret.buttonIndex;
				                    if (index == 1) {//确定
				                        // openVideoWin(doc, title);
				                        pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, doc, title);
				                    }
				                });
				            }else{
				            	// openVideoWin(doc, title);
				            	pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, doc, title);
				            }
						} else {
							if (is_encr == 1) {//加密
								var CFBaiDuDoc = api.require('CFBaiDuDoc');
						        CFBaiDuDoc.startDocActivityForResult({
						            docId:baidu_cloud_id,//文档ID
						            title:title,//文档标题
						            token:"TOKEN",//文档token，离线加载时不验证。
						            host:"BCEDOC",//文档所属站点
						            docType:"doc" //文档类型，可取值为ppt 和 doc
						        },function(){
						        });
							}else{
								api.openWin({useWKWebView:true,
									name : 'Student_FreeCourseDoc',
									url : 'Student_FreeCourseDoc.html',
									pageParam : {
										title : title,
										doc : doc
									}
								});
							}
						}
					}
				}
			});
			$('.download_img').unbind('click');
			$('.download_img').click(function(event){
				var fileid = $(this).attr('id');
				var filename = $(this).attr('file_name');
				var fileurl = $(this).attr('file_path');
				if($(this).hasClass('isNotDownload')){//未下载
					//判断网路状态
					var connectionType = api.connectionType;
		            if (connectionType != 'wifi') {
		            	if (connectionType == 'none') {
		            		api.toast({
		            		    msg: '暂无网络，请检查您的网络'
		            		});
		            	}else{
		            		api.confirm({
			                    title: '提示',
			                    msg: '您当前处于移动数据网络下，是否继续下载',
			                    buttons: ['确定', '取消']
			                }, function(ret, err) {
			                    var index = ret.buttonIndex;
			                    if (index == 1) {//确定
									api.sendEvent({
									    name: 'startDownloadFileNotifi',
									    extra: {
									        fileid : fileid,
											filename : filename,
											fileurl : fileurl
									    }
									});
			                    }
			                });
		            	}
		            }else{
		            	api.sendEvent({
						    name: 'startDownloadFileNotifi',
						    extra: {
						        fileid : fileid,
								filename : filename,
								fileurl : fileurl
						    }
						});
		            }
				}
				//停止事件传递
				event.stopPropagation();
			});
		}
		// content_type folder files
		function fileAndFolderHtmlString(data) {
			var imgPath = imagePathWithUrlPath(data);
			//默认文件夹
			var fileSize = '';
			var rightImg = '';
			// var leftImg = '<img class="mui-media-object mui-pull-left" style="padding: 6px;" src="../../image/icon_wenjianjia.png" >';
			var leftImg = '<img class="mui-media-object mui-pull-left" style="padding: 6px;" src="'+imgPath+'" >';
			if (data.content_type == 'files') {//文件
				// fileSize = '<span class="file_size">\
				// 						1.5MB\
				// 					</span>';//无大小暂时不显示
				// rightImg = '<img id="' + data.fileid + '" src="../../image/iconO_xiazai.png" alt="" class="download_img" file_name="' + data.fileName + '" file_path="' + data.filePath + '" hidden="hidden">';
				leftImg = '<img class="mui-media-object mui-pull-left" style="padding: 6px;" src="'+imgPath+'" >';
			}
			return '<li class="mui-table-view-cell mui-media file_cell" id="' + data.id + '" file_path="' + data.filePath + '" file_name="' + data.fileName + '" is_encr="'+data.is_encr+'" baidu_cloud_id="'+data.baidu_cloud_id+'" baidu_cloud_id_url="'+data.baidu_cloud_id_url+'">' + '<a href="javascript:;">' + leftImg + '<div class="mui-media-body">' + '<p class="mui-ellipsis base_dark_grey font14">' + '<span class="message_title">' + data.names + '</span>' + '</p>' + '<p class="mui-ellipsis base_light_gray font12 content_p">' + '<span class="message_content">' +
			// '<span class="file_submit_time">\
			// 	2017-01-02 14:20\
			// </span>'+//无时间暂时不显示
			fileSize + '</span>' + rightImg + '</p>' + '</div>' + '</a>' + '</li>';
		}

		function addFileCellClick() {
			$('.file_cell').unbind('click');
			$('.file_cell').click(function(event) {
				if (api.pageParam.content_type == 'folder') {//文件夹
					// api.openWin({useWKWebView:true,
					// 	name : 'Student_FreeCourseFolderDetailNew',
					// 	url : 'Student_FreeCourseFolderDetailNew.html',
					// 	pageParam : api.pageParam
					// });
				} else {
					var doc = $(this).attr('file_path');
					var title = $(this).attr('file_name');
					var is_encr = $(this).attr('is_encr');
					var baidu_cloud_id = $(this).attr('baidu_cloud_id');
					var baidu_cloud_id_url = $(this).attr('baidu_cloud_id_url');
					var fileid = MD5(doc);
					if ($('#' + fileid).hasClass('isDownload')) {
						openLocalFile(api.cacheDir + '/freeCourseFile/' + fileid + '/' + title);
					} else {
						var arr = new Array('jpg', 'png', 'jpeg', 'bmp');
						var gifArr = new Array('gif');
						var arr1 = new Array('swf', 'mp4');
						var ext = doc.replace(/.+\./, "");
					
						if (gifArr.toString().indexOf(ext) > -1){
							openGif(doc);
						}else if (arr.toString().indexOf(ext) > -1) {
							openImage(doc);
						} else {
							if (arr1.toString().indexOf(ext) > -1) {
								var connectionType = api.connectionType;
					            if (connectionType != 'wifi' && connectionType != 'none') {
					            	api.confirm({
					                    title: '提示',
					                    msg: '您当前处于移动数据网络下，是否继续播放',
					                    buttons: ['确定', '取消']
					                }, function(ret, err) {
					                    var index = ret.buttonIndex;
					                    if (index == 1) {//确定
					                        // openVideoWin(doc, title);
					                        pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, doc, title);
					                    }
					                });
					            }else{
					            	// openVideoWin(doc, title);
					            	pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, doc, title);
					            }
							} else {
								if (is_encr == 1) {//加密
									var CFBaiDuDoc = api.require('CFBaiDuDoc');
							        CFBaiDuDoc.startDocActivityForResult({
							            docId:baidu_cloud_id,//文档ID
							            title:title,//文档标题
							            token:"TOKEN",//文档token，离线加载时不验证。
							            host:"BCEDOC",//文档所属站点
							            docType:"doc" //文档类型，可取值为ppt 和 doc
							        },function(){
							        });
								}else{
									api.openWin({useWKWebView:true,
										name : 'Student_FreeCourseDoc',
										url : 'Student_FreeCourseDoc.html',
										pageParam : {
											title : title,
											doc : doc
										}
									});
								}
							}
						}
					}
				}
			});
			// $('.download_img').unbind('click');
			// $('.download_img').click(function(event) {
			// 	var fileid = $(this).attr('id');
			// 	var filename = $(this).attr('file_name');
			// 	var fileurl = $(this).attr('file_path');
			// 	if ($(this).hasClass('isNotDownload')) {//未下载
			// 		api.sendEvent({
			// 			name : 'startDownloadFileNotifi',
			// 			extra : {
			// 				fileid : fileid,
			// 				filename : filename,
			// 				fileurl : fileurl
			// 			}
			// 		});
			// 	}
			// 	//停止事件传递
			// 	event.stopPropagation();
			// });
			$('.download_img').unbind('click');
			$('.download_img').click(function(event){
				var fileid = $(this).attr('id');
				var filename = $(this).attr('file_name');
				var fileurl = $(this).attr('file_path');
				if($(this).hasClass('isNotDownload')){//未下载
					//判断网路状态
					var connectionType = api.connectionType;
		            if (connectionType != 'wifi') {
		            	if (connectionType == 'none') {
		            		api.toast({
		            		    msg: '暂无网络，请检查您的网络'
		            		});
		            	}else{
		            		api.confirm({
			                    title: '提示',
			                    msg: '您当前处于移动数据网络下，是否继续下载',
			                    buttons: ['确定', '取消']
			                }, function(ret, err) {
			                    var index = ret.buttonIndex;
			                    if (index == 1) {//确定
									api.sendEvent({
									    name: 'startDownloadFileNotifi',
									    extra: {
									        fileid : fileid,
											filename : filename,
											fileurl : fileurl
									    }
									});
			                    }
			                });
		            	}
		            }else{
		            	api.sendEvent({
						    name: 'startDownloadFileNotifi',
						    extra: {
						        fileid : fileid,
								filename : filename,
								fileurl : fileurl
						    }
						});
		            }
				}
				//停止事件传递
				event.stopPropagation();
			});
		}
		function openVideoWin(videourl, videotitle){
			var videoPlayer = api.require('videoPlayer');
			videoPlayer.play({
			    path : videourl,
			    texts: {
			        head: {
			            title: videotitle
			        }
			    },
			    styles : {
			    	head : {
			    		backSize : 24,
			    		backImg : 'widget://image/vp_back.png',
			    		setSize : 24,
			    		setImg : 'widget://image/vp_more.png'
			    	},
			    	foot :{
			    		playSize : 24,
			    		playImg : 'widget://image/vp_play.png',
			    		pauseImg : 'widget://image/vp_pause.png',
			    		nextSize : 24,
			    		nextImg : 'widget://image/vp_next.png'
			    	}
			    }
			}, function(ret, err) {
		        
			});
		}
		function setupNotifi() {
			api.addEventListener({
				name : 'downloadFreeCourseFileNotifi'
			}, function(ret, err) {
				var notifiValue = ret.value;
				var fileId = notifiValue.fileid;
				var notifiRet = notifiValue.ret;
				var width = "width:" + notifiRet.percent + "%;";
				if(notifiRet.state == 2){
					api.toast({
					    msg: '下载失败，失败原因：'+notifiRet.msg
					});
				};
				$('#progress' + fileId).css('style', width);
				if (notifiRet.state == 1) {//下载完成
					$('#progress' + fileId).css('style', 'width(0)');
					$('#' + fileId).removeClass('isNotDownload');
					$('#' + fileId).addClass('isDownload');
					$('#' + fileId).hide();
				} else if (notifiRet.state == 2) {//下载失败
					$('#progress' + fileId).css('style', 'width(0)');
					$('#' + fileId).removeClass('isDownload');
					$('#' + fileId).addClass('isNotDownload');
					$('#' + fileId).attr('src', '../../image/iconO_xiazai.png');
					$('#' + fileId).show();
				}
			});
			api.addEventListener({
			    name: 'keyback'
			}, function(ret, err) {
			    api.closeWin({
		    	    name: 'Student_Free_bewrite'
		    	});
		    	api.closeWin();
			});
		}

		function backClick() {
			api.closeWin({
	    	    name: 'Student_Free_bewrite'
	    	});
			api.closeWin();
		}
		function openbewrite(){
			api.openWin({useWKWebView:true,
			    name: 'Student_Free_bewrite',
			    url: 'Student_Free_bewrite.html',
			    pageParam: {
			        title : api.pageParam.cdetailtitle,
					bewrite : api.pageParam.bewrite,
					is_dis_bewrite : api.pageParam.is_dis_bewrite
			    }
			});
		}
	</script>
</html>
